﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenThesis.Extensions.FX;
using OpenThesis.DTO.FX;
using System.ComponentModel.Composition;

namespace OpenThesis.DemoExtensions
{
	/// <summary>
	/// This is an example of a repository that can be imported as an extension to the service
	/// </summary>
	[Export(typeof(ITradesRepository))]
    public class InMemoryTradeRepository : ITradesRepository
    {
		public IList<Trade> GetActiveTrades(Account account, DateTime atTime)
		{
			// Here we would normaly get the trades from a database or other permanent storage

			var USD = new Currency("USD");
			var CAD = new Currency("CAD");
			var EUR = new Currency("EUR");

			//var account = new Account("Test Account");
			var contract1 = new SpotContract("EUR/USD", EUR, USD, 2);
			var contract2 = new SpotContract("USD/CAD", USD, CAD, 1);
			var contract3 = new ForwardContract("EUR/USD", EUR, USD, new DateTime(2013, 6, 25));

			var trades = new List<Trade>()
			{
				new Trade(new DateTime(2013,2,27,16,46,30),
					account,
					new Position(
						contract1,
						100, 
						DateTime.Now.Date.AddDays(contract1.DaysToDelivery)),
					new Quote()),
				new Trade(new DateTime(2013,2,27,16,47,30),
					account,
					new Position(
						contract1,
						200, 
						DateTime.Now.Date.AddDays(contract1.DaysToDelivery)),
					new Quote()),
				new Trade(new DateTime(2013,2,27,16,48,30),
					account,
					new Position(
						contract2,
						300, 
						DateTime.Now.Date.AddDays(contract2.DaysToDelivery)),
					new Quote()),
				new Trade(new DateTime(2013,2,27,16,49,30),
					account,
					new Position(
						contract2,
						-100, 
						DateTime.Now.Date.AddDays(contract2.DaysToDelivery)),
					new Quote()),
				new Trade(new DateTime(2013,2,27,16,49,45),
					account,
					new Position(
						contract3,
						400, 
						contract3.DeliveryDate),
					new Quote())
			};
			return trades;
		}
	}
}
